<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
    <style>
        .active {
            background-color: purple;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul>
            <!-- $emit('update:show', false -->
            <!-- <li v-for="(item,id) in courses" :key=id v-text="item.name" :class={active:(item.name===choice)} @click="choice = item.name
            "></li> -->
            <li v-for="(item,id) in courses" :key=id v-text="item.name+'and'+item.price" :style="{backgroundColor:(item.name===choice?'pink':'transparent')}" @click="choice = item.name
            "></li>
        </ul>
        <input v-model.number="inputValue" type="number" step="1" />
        <button @click="addPrice">添加价格</button>
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                inputValue: 0,
                choice: "",
                courses: [{
                    name: "java"
                }, {
                    name: "c"
                }, {
                    name: "c++"
                }, {
                    name: "javascript"
                }, ]
            },
            methods: {
                addPrice() {
                    this.courses.forEach(element => {
                        this.$set(element, "price", this.inputValue)
                    });
                    console.log(this.courses)
                }
            },
        })
    </script>
</body>

</html>